<?php

$xtpl = new XTemplate("modules/home/banner.htm");

$page = $_GET['page'];
//--

//--
$waypathlink = '&raquo;&nbsp;<a href="#" class="waypath_sub">Banner Management</a>';
$xtpl_main->assign("waypathlink",$waypathlink);
//--
//--
//--
$add_button = $GUI->button_ren("New","javascript: add('?mod=home&act=banner_task');");
$xtpl->assign("add_button",$add_button);
//--
$delete_button = $GUI->button_ren("Delete","javascript: del('DELETE', document.frmAddnews);");
$xtpl->assign("delete_button",$delete_button);
//--
//--
//--
$limit = 20;
$pagegroup_size = 10;
if (!$page||$page==0){
	$page=1;
}
$offset = ($page-1)*$limit;
//////
/////////////////////////
$sql_c = "SELECT COUNT(*) AS total_msg FROM {$DP}banner ";
$rs_c = mysql_query($sql_c);
list($numrec)=mysql_fetch_row($rs_c);
//////////////////////////
$rs = $DB->ZenDataList('banner','','','id DESC',$offset.','.$limit);

$no=1;
while($row = mysql_fetch_array($rs)){
    $row[no]=$no++;	
    if($no%2!=0)
            $row['class'] = "row1";
    else 
            $row['class'] = "row2";
    //--
    $row[edit_link] = '?mod=home&act=banner_task&id='.$row['id'].'';
    if($row['image']!=''){	
        $row['show_image']='<img src="../upload/banner/thumb'.$row['image'].'" border="0" width="120">';
    }

    //--
    $xtpl->assign("list",$row);
    $xtpl->parse("center.list");
}
//--
$pages = pagenavigator($page,$numrec,$limit,$pagegroup_size,"row0","?mod=home&act=banner");
$xtpl->assign("page",$page);
$xtpl->assign("pages",$pages);
$xtpl->assign("numrec",$numrec);

//--
//--
//--
if($_POST['type'] == "DELETE"){
	$checked_delete = $_POST[checked_delete];
	for ($i=0;$i<count($checked_delete);$i++) {
		$delete_list.= $checked_delete[$i].",";
	}
	if($delete_list){
		$delete_list = substr($delete_list,0,strlen($delete_list)-1);
		$delete_split=explode(",",$delete_list);
		for($i=0;$i<count($delete_split);$i++){
			//--
			$sql = "SELECT image FROM {$DP}banner WHERE id='".$delete_split[$i]."'";
			$row = $DB->SQLrecordset($sql);
			if($row[image] != ''){
				$dir_ = "../upload/banner/thumb".$row['image'];
				if(is_file($dir_)) @unlink($dir_);
                                $dir_ = "../upload/banner/".$row['image'];
				if(is_file($dir_)) @unlink($dir_);
                                
			}	
			//--	
			$sql = "DELETE FROM {$DP}banner WHERE id='".$delete_split[$i]."'";
			mysql_query($sql);
		}
	}
	if($_GET['page'] != '')
		$GUI->redir('?mod=home&act=banner&page='.$_GET['page']);
	else
		$GUI->redir('?mod=home&act=banner');
}

?>